<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <!-- 三个组件实例 -->
        <cpn></cpn>
        <cpn></cpn>
        <cpn></cpn>
    </div>
    <template id='cpn'>
        <div>
            <h2>当前计数：{{count}}</h2>
            <button @click="increment">+</button>
            <button @click="decrement">-</button>
        </div>
    </template>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script>
        //1.注册组件
        Vue.component('cpn',{
            template:'#cpn',
            //为什么组件的data是一个函数：为了不共用一个对象，让每个组件有一个数据对象
            data(){
               return {
                   count:0
               }
            },
            methods:{
                increment(){
                    this.count++
                },
                decrement(){
                    this.count--
                }

            }
        })
        const app=new Vue({
            el:'#app',
            data:{
                message:'vuejs'
            }
        })
    </script>
</body>
</html>